package com.parsechina.hpush.broker.parser;


import io.netty.handler.codec.mqtt.*;

/**
 * @author linfeng
 * @since 2016/11/22
 */
public class ConnAckMessage extends PushMessage {
    private static final long serialVersionUID = -1157015296673105675L;

    private MqttConnAckMessage connAckMessage;

    public ConnAckMessage(MqttConnAckMessage msg) {
        super(msg);
        this.connAckMessage = msg;
    }

    public ConnAckMessage(MqttMessage msg) {
        super(msg);
    }

    public static ConnAckMessageBuilder buildConnAckMessage() {
        return new ConnAckMessageBuilder();
    }

    public static class ConnAckMessageBuilder extends MessageBuilder {
        private MqttConnectReturnCode returnCode;
        private boolean sessionPresent;

        public ConnAckMessageBuilder setReturnCode(MqttConnectReturnCode returnCode) {
            this.returnCode = returnCode;
            return this;
        }

        public ConnAckMessageBuilder setSessionPresent(boolean sessionPresent) {
            this.sessionPresent = sessionPresent;
            return this;
        }

        @Override
        public MqttConnAckMessage build() {
            MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.CONNACK, false, MqttQoS.AT_MOST_ONCE, false, 0);
            MqttConnAckVariableHeader variableHeader = new MqttConnAckVariableHeader(returnCode, sessionPresent);
            return new MqttConnAckMessage(fixedHeader, variableHeader);
        }

    }
}
